package org.bigjava.user.service.impl;

import org.bigjava.bean.Topic;
import org.bigjava.common.Constant;
import org.bigjava.user.mapper.TopicMapper;
import org.bigjava.user.mapper.UserFunctionMapper;
import org.bigjava.user.service.AjaxService;
import org.bigjava.user.util.AESUtil;
import org.bigjava.user.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AjaxServiceImpl implements AjaxService {
    @Autowired
    UserFunctionMapper userFunctionMapper;
    @Autowired
    TopicMapper topicMapper;
    AESUtil aesUtil = new AESUtil();

    @Override
    public boolean updateAttention(String userId, long topicId) {
        long id = Long.parseLong(aesUtil.iddecrypt(userId));
        System.out.println(id + "解密");
        userFunctionMapper.updateAttention(id, topicId);
        int state = userFunctionMapper.queryAttentionState(id, topicId);
        if (state == 1) return true;//未关注
        else return false;//已关注
    }

    @Override
    public boolean updateCollect(String userId, long postId) {
        long id = Long.parseLong(aesUtil.iddecrypt(userId));
        userFunctionMapper.updateCollect(id, postId);
        int state = userFunctionMapper.queryCollectState(id, postId);
        if (state == 1) return true;//未关注
        else return false;//已关注
    }

    @Override
    public boolean updatePostPrivacy(long postId) {
        userFunctionMapper.updatepostprivacy(postId);
        int privacy = userFunctionMapper.querypostprivacy(postId);
        if (privacy == 1) return true;
        else return false;
    }


    //实现首页热门话题分页数据查询
    @Override
    public List<Topic> indexhottopicpage(int startPage) {

        return topicMapper.indexHotTopic((startPage - 1) * Constant.hotTopicPage, Constant.hotTopicPage);
    }


}
